# -*- coding: utf-8 -*-
"""
@Time: 2021/12/23 08:55
@Author: jins
@File: table_demandd.py
@Introduction: demandd表造数据
"""
from common.mysqlDataOperate import OperateMysql
import random
from datetime import datetime, timedelta

EfficacyOptions_list = [1, 2, 4, 8]
PhaseOptions_list = [1, 2, 4, 8]
combination_list = [(i, j) for i in EfficacyOptions_list for j in PhaseOptions_list]


def insert(start):
    op = OperateMysql()
    for j in range(start + 1, start + 3):
        for k in combination_list:
            data_time = datetime(2019, 11, 1, 0, 0, 0)
            fmt = '%Y%m%d'
            fmt_2 = '%H%M%S'
            for i in range(30):
                DateNum = int(data_time.strftime(fmt))
                device_id = 10000000 + j
                TotalValue = random.uniform(1000.0, 2000.0)
                TotalDateNum = int(data_time.strftime(fmt))
                TotalTimeNum = int(data_time.strftime(fmt_2))
                PikeValue = random.uniform(500.0, 800.0)
                PikeDateNum = int(data_time.strftime(fmt))
                PikeTimeNum = int(data_time.strftime(fmt_2))
                PeakValue = random.uniform(300.0, 500.0)
                PeakDateNum = int(data_time.strftime(fmt))
                PeakTimeNum = int(data_time.strftime(fmt_2))
                FlatValue = random.uniform(100.0, 300.0)
                FlatDateNum = int(data_time.strftime(fmt))
                FlatTimeNum = int(data_time.strftime(fmt_2))
                ValeValue = random.uniform(50.0, 100.0)
                ValeDateNum = int(data_time.strftime(fmt))
                ValeTimeNum = int(data_time.strftime(fmt_2))
                CallDateNum = int(data_time.strftime(fmt))
                CallTimeNum = int(data_time.strftime(fmt_2))
                UpdateTime = data_time.timestamp() * 1000
                sql = f"""INSERT INTO xlcloud.demandd19b
                VALUES
                    (   
                        {DateNum},
                        {device_id},
                        {k[0]},
                        {k[1]},
                        {TotalValue},
                        {TotalDateNum},
                        {TotalTimeNum},
                        {PikeValue},
                        {PikeDateNum},
                        {PikeTimeNum},
                        {PeakValue},
                        {PeakDateNum},
                        {PeakTimeNum},
                        {FlatValue},
                        {FlatDateNum},
                        {FlatTimeNum},
                        {ValeValue},
                        {ValeDateNum},
                        {ValeTimeNum},
                        {CallDateNum},
                        {CallTimeNum},
                        1,
                        1,
                        {UpdateTime}
                     )
                        """
                op.batch_excute(sql)
                data_time += timedelta(days=1)
            op.commit()
    op.close()


if __name__ == '__main__':
    insert(0)
